/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presentation.view.custom;

import presentation.view.custom.ListItem;
import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 *
 * @author Joanna 8a
 */
public class ITListCellRenderer extends JLabel implements ListCellRenderer {

      public ITListCellRenderer () {
      // Don't paint behind the component
          setOpaque(true);
      }

 // Set the attributes of the 
 //class and return a reference
    @Override
  public Component 
   getListCellRendererComponent(JList list,
        Object value, // value to display
        int index,    // cell index
        boolean iss,  // is selected
        boolean chf)  // cell has focus?
  {
      // Set the text and color 
      //background for rendering
      setText(((ListItem)value).getValue(
           ));
      setBackground(((
       ListItem)value).getColor());

      // Set a border if the list 
      //item is selected 
            if (iss) {
                setBorder(
                 BorderFactory.createLineBorder(
                  Color.blue, 2));
            } else {
                setBorder(
                 BorderFactory.createLineBorder(
                  list.getBackground(), 2));
            }
             return this;
        }
     }

